home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / c / AMesaRTL.lha / Mesa-2.6 / amiga / src-glut / glutCreateWindow.c < prev    next >
C/C++ Source or Header  |  1998-09-19  |  6KB  |  218 lines

  1. /*
  2.  * Amiga GLUT graphics library toolkit
  3.  * Version:  2.0
  4.  * Copyright (C) 1998 Jarno van der Linden
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the Free
  18.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21.  
  22. /*
  23.  * glutCreateWindow.c
  24.  *
  25.  * Version 1.0  27 Jun 1998
  26.  * by Jarno van der Linden
  27.  * jarno@kcbbs.gen.nz
  28.  *
  29.  * Version 1.1  02 Aug 1998
  30.  * by Jarno van der Linden
  31.  * jarno@kcbbs.gen.nz
  32.  *
  33.  * - Quantizer plugin support added
  34.  *
  35.  * Version 2.0  19 Sep 1998
  36.  * by Jarno van der Linden
  37.  * jarno@kcbbs.gen.nz
  38.  *
  39.  * - Changed to v2 mesa.library and quantizer usage
  40.  * - Changed to runtime library format
  41.  * - Changed quantizer to output handler
  42.  * - Bugfix: TAG_SKIP values were wrong, fixed to skip 1
  43.  *   instead of 2
  44.  * - Output screen/window created only when output handler
  45.  *   doesn't make one or handerwindow==FALSE
  46.  *
  47.  */
  48.  
  49.  
  50. #include <proto/intuition.h>
  51. #include <proto/gadtools.h>
  52.  
  53. #include <stdlib.h>
  54.  
  55. #include "glutstuff.h"
  56. #include "gl/outputhandler.h"
  57.  
  58. extern VOID CloseWindowSafely(struct Window *win);
  59.  
  60. struct NewMenu defmenu[] = {
  61.     { NM_TITLE,    "Left Menu",    0, 0, 0, 0, },
  62.     { NM_TITLE,    "Middle Menu",    0, 0, 0, 0, },
  63.     { NM_TITLE,    "Right Menu",    0, 0, 0, 0, },
  64.     { NM_END,    NULL,            0, 0, 0, 0, }
  65. };
  66.  
  67.  
  68. __asm __saveds int glutCreateWindow( register __a0 const char *title )
  69. {
  70.     struct GlutWindow *gw;
  71.     struct Screen *screen;
  72.     WORD zoom[4];
  73.  
  74.     gw = calloc(1,sizeof(struct GlutWindow));
  75.     if(gw)
  76.     {
  77.         gw->context = NULL;
  78.  
  79.         if(glutstuff.handlerwindow)
  80.         {
  81.             gw->mywindow = FALSE;
  82.  
  83.             gw->context = AmigaMesaRTLCreateContext(
  84.                                 OH_Output,                0,
  85.                                 OH_OutputType,            "Window",
  86.                                 AMRTL_RGBAMode,            glutstuff.rgba,
  87.                                 TAG_SKIP,                glutstuff.oh == NULL ? 1 : 0,
  88.                                 AMRTL_OutputHandler,    glutstuff.oh,
  89.                                 TAG_SKIP,                glutstuff.ohversion == -1 ? 1 : 0,
  90.                                 AMRTL_OutputHandlerVersion,    glutstuff.ohversion,
  91.                                 TAG_END);
  92.             if(gw->context)
  93.             {
  94.                 /* Hijack the window */
  95.  
  96.                 AmigaMesaRTLGetOutputHandlerAttr(OH_Output,gw->context,&gw->window);
  97.                 if (gw->window->Flags & WFLG_DRAGBAR)
  98.                     ChangeWindowBox(gw->window,glutstuff.initposx,glutstuff.initposy,glutstuff.initwidth,glutstuff.initheight);
  99.                 if (!(gw->window->Flags & WFLG_BORDERLESS))
  100.                     SetWindowTitles(gw->window,title,~0);
  101.                 gw->window->UserPort = glutstuff.msgport;
  102.             }
  103.         }
  104.  
  105.         if(!gw->context)
  106.         {
  107.             gw->mywindow = TRUE;
  108.  
  109.             screen = LockPubScreen(glutstuff.pubscreenname);
  110.             zoom[0] = glutstuff.initposx;
  111.             zoom[1] = glutstuff.initposy;
  112.             zoom[2] = glutstuff.initwidth;
  113.             zoom[3] = glutstuff.initheight;
  114.             gw->window = OpenWindowTags(NULL,
  115.                     WA_Title,                title,
  116.                     WA_PubScreen,            screen,
  117.  
  118.                     WA_Left,                glutstuff.initposx,
  119.                     WA_Top,                    glutstuff.initposy,
  120.                     WA_Width,                glutstuff.initwidth,
  121.                     WA_Height,                glutstuff.initheight,
  122.                     WA_MinWidth,            32,
  123.                     WA_MinHeight,            32,
  124.                     WA_MaxWidth,            ~0,
  125.                     WA_MaxHeight,            ~0,
  126.  
  127.                     WA_NoCareRefresh,        TRUE,
  128.                     WA_Activate,            TRUE,
  129.  
  130.                     WA_CloseGadget,            TRUE,
  131.                     WA_DragBar,                TRUE,
  132.                     WA_SizeGadget,            TRUE,
  133.                     WA_DepthGadget,            TRUE,
  134.                     WA_Zoom,                zoom,
  135.  
  136.                     TAG_END);
  137.             UnlockPubScreen(NULL,screen);
  138.  
  139.             if(gw->window)
  140.             {
  141.                 gw->window->UserPort = glutstuff.msgport;
  142.                 gw->context = AmigaMesaRTLCreateContext(
  143.                                     OH_Output,                gw->window,
  144.                                     OH_OutputType,            "Window",
  145.                                     AMRTL_RGBAMode,            glutstuff.rgba,
  146.                                     TAG_SKIP,                glutstuff.oh == NULL ? 1 : 0,
  147.                                     AMRTL_OutputHandler,    glutstuff.oh,
  148.                                     TAG_SKIP,                glutstuff.ohversion == -1 ? 1 : 0,
  149.                                     AMRTL_OutputHandlerVersion,    glutstuff.ohversion,
  150.                                     TAG_END);
  151.             }
  152.         }
  153.  
  154.         if(gw->context)
  155.         {
  156.             if(ModifyIDCMP(gw->window,IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_MENUPICK | IDCMP_MOUSEBUTTONS | IDCMP_INTUITICKS | IDCMP_CHANGEWINDOW))
  157.             {
  158.                 gw->winid = stuffGetNewWinID();
  159.                 gw->window->UserData = (APTR)gw;
  160.  
  161.                 gw->vi = GetVisualInfo(gw->window->WScreen, TAG_END);
  162.  
  163.                 gw->menu = CreateMenus(defmenu, TAG_END);
  164.                 LayoutMenus(gw->menu, gw->vi, TAG_END);
  165.                 SetMenuStrip(gw->window, gw->menu);
  166.  
  167.                 gw->qualifiers = 0;
  168.                 gw->mousex = -1;
  169.                 gw->mousey = -1;
  170.  
  171.                 gw->winx = gw->wincurx = gw->window->LeftEdge;
  172.                 gw->winy = gw->wincury = gw->window->TopEdge;
  173.                 gw->winwidth = gw->wincurwidth = gw->window->Width;
  174.                 gw->winheight = gw->wincurheight = gw->window->Height;
  175.  
  176.                 stuffLinkInWin(gw);
  177.  
  178.                 if(glutstuff.depth)
  179.                     glEnable(GL_DEPTH_TEST);
  180.  
  181.                 gw->displayfunc = NULL;
  182.                 gw->keyboardfunc = NULL;
  183.                 gw->reshapefunc = NULL;
  184.                 gw->visibilityfunc = NULL;
  185.                 gw->specialfunc = NULL;
  186.                 gw->mousefunc = NULL;
  187.  
  188.                 gw->needreshape = FALSE;
  189.                 gw->needreshapegui = TRUE;
  190.                 gw->needposition = FALSE;
  191.                 gw->needpositiongui = TRUE;
  192.                 gw->needredisplay = TRUE;
  193.                 gw->needvisibility = TRUE;
  194.                 gw->visible = TRUE;
  195.                 gw->needleftmenu = TRUE;
  196.                 gw->needmiddlemenu = TRUE;
  197.                 gw->needrightmenu = TRUE;
  198.  
  199.                 return(gw->winid);
  200.             }
  201.  
  202.             if(!gw->mywindow)
  203.             {
  204.                 gw->window->UserPort = NULL;
  205.                 ModifyIDCMP(gw->window, 0L);
  206.             }
  207.             AmigaMesaRTLDestroyContext(gw->context);
  208.         }
  209.  
  210.         if(gw->window && gw->mywindow)
  211.             CloseWindowSafely(gw->window);
  212.  
  213.         free(gw);
  214.     }
  215.  
  216.     return(0);
  217. }
  218.